package main

import (
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	"github.com/labstack/gommon/log"
	"go-web-template/api_template"
	"go-web-template/db_template"
	"go-web-template/ws_template"
	"net/http"
)

func main() {
	//mysql
	defer db_template.DB.Close()
	defer db_template.RDB.Close()
	//db_template.UserSave()
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	//user router
	e.POST("/form-data", api_template.SaveUser)
	e.POST("/multipart/form-data", api_template.SaveUser2)
	e.POST("/json-result", api_template.ReturnJson)
	e.GET("/users/:id", api_template.GetUser)
	e.GET("/query-param", api_template.ShowUser)

	//websocket router
	e.GET("/ws", ws_template.Hello)
	e.GET("/ws/:client_id", ws_template.HelloUser)
	e.POST("/ws/to_message", ws_template.WriteMessageToClient)

	//server
	s := http.Server{
		Addr:    ":8080",
		Handler: e,
		//ReadTimeout: 30 * time.Second, // customize http.Server timeouts
	}
	log.Info("The service is started on port 8080.")
	if err := s.ListenAndServe(); err != http.ErrServerClosed {
		log.Fatal(err)
	}

}
